using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_webparts_Plug_ins_Survey_SurveyManagement : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string action = Request.QueryString["action"];
        string controlName = null;
        if (action != null)
        {
            if (action.Equals("surveylist", StringComparison.OrdinalIgnoreCase))
            {
                controlName = "SurveyList.ascx";
            }
            else if (action.Equals("surveyedit", StringComparison.OrdinalIgnoreCase))
            {
                controlName = "SurveyInput.ascx";
            }
            else if (action.Equals("surveyadd", StringComparison.OrdinalIgnoreCase))
            {
                controlName = "SurveyInput.ascx";
            }
            else if (action.Equals("surveyview", StringComparison.OrdinalIgnoreCase))
            {
                controlName = "SurveyDetail.ascx";
            }
            else if (action.Equals("detailadd", StringComparison.OrdinalIgnoreCase))
            {
                controlName = "SurveyDetailInput.ascx";
            }
            else if (action.Equals("detailedit", StringComparison.OrdinalIgnoreCase))
            {
                controlName = "SurveyDetailInput.ascx";
            }
            else if (action.Equals("moveup", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    this.MoveUp(Int32.Parse(Request.QueryString["detailid"]));
                }
                catch (Exception) { }
                Response.Redirect("?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"] + "&action=surveyview&surveyid=" + Request.QueryString["surveyid"]);
            }
            else if (action.Equals("movedown", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    this.MoveDown(Int32.Parse(Request.QueryString["detailid"]));
                }
                catch (Exception) { }
                Response.Redirect("?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"] + "&action=surveyview&surveyid=" + Request.QueryString["surveyid"]);
            }
            else if (action.Equals("detaildel", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    this.Delete(Int32.Parse(Request.QueryString["detailid"]));
                }
                catch (Exception) { }
                Response.Redirect("?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"] + "&action=surveyview&surveyid=" + Request.QueryString["surveyid"]);
            }
            else
            {
                controlName = "SurveyList.ascx";
            }
        }
        else
        {
            controlName = "SurveyList.ascx";
        }

        if (controlName != null)
        {
            Control ctrl = LoadControl(controlName);
            this.Controls.Add(ctrl);
        }
    }

    private void MoveUp(int id)
    {
        try
        {
            NTTHAO.Web.BL.Survey.SurveyDetail detail = new NTTHAO.Web.BL.Survey.SurveyDetail(id);
            detail.MoveUp();
        }
        catch (Exception) { }
    }

    private void MoveDown(int id)
    {
        try
        {
            NTTHAO.Web.BL.Survey.SurveyDetail detail = new NTTHAO.Web.BL.Survey.SurveyDetail(id);
            detail.MoveDown();
        }
        catch (Exception) { }
    }

    private void Delete(int id)
    {
        try
        {
            NTTHAO.Web.BL.Survey.SurveyDetail detail = new NTTHAO.Web.BL.Survey.SurveyDetail(id);

            detail.Delete();
        }
        catch (Exception) { }
    }
}
